package com.medical.device.common;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * 自定义分页
 * @author yy
 * @param <T>
 */
@Data
public class PageInfo<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 当前页
     */
    private long currentPage;

    /**
     * 每页的数量
     */
    private long pageSize;

    /**
     * 当前页的数量
     */
    private long size;

    /**
     * 总记录数
     */
    private long total;

    /**
     * 总页数
     */
    private long pages;

    /**
     * 结果集
     */
    private List<T> list;

    /**
     * 是否有下一页
     */
    private boolean hasNext;

    public PageInfo() {
    }

    /**
     * 包装Page对象
     *
     * @param page
     */
    public static PageInfo getPageInfo(IPage page) {
        PageInfo pageInfo = new PageInfo();
        Page list = (Page) page;
        pageInfo.currentPage = list.getCurrent();
        pageInfo.pageSize = list.getSize();
        pageInfo.pages = list.getPages();
        pageInfo.list = list.getRecords();
        pageInfo.size = list.getRecords().size();
        pageInfo.total = list.getTotal();
        pageInfo.hasNext = list.hasNext();
        return pageInfo;
    }
}
